home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / ooptut34.zip / TP / OOPTUTOR / TVISION.TXT < prev    next >
Text File  |  1993-06-12  |  22KB  |  444 lines

  1.                         TURBO VISION.
  2.                         ------------- 
  3.       
  4. Introduction.
  5. -------------
  6.  
  7.  Since Turbo Vision makes use of object-oriented techniques, including
  8.  inheritance and polymorphism, it is necessary to be completely familiar
  9.  with object-oriented programming.  Furthermore the object instances are
  10.  dynamically allocated on the heap, so that familiarity with pointers and
  11.  dynamic variables is also essential.  The extended syntax of the 'New'
  12.  procedure, which allows the allocation of space on the heap for an object
  13.  and its initialization within the one procedure must also be appreciated.
  14.  This new procedure is now invoked with two parameters, the pointer name as
  15.  the first parameter and the constructor invocation as the second parameter.
  16.  All these topics are covered in the notes on Advanced Data Structures and
  17.  Object-Oriented Programming.
  18.  
  19.  In OOP parlance, an 'object type' is an abstraction that provides a
  20.  template for specific objects, which are themselves called 'instances' of
  21.  that object type.  In Turbo Vision, the templates or object types all start
  22.  with the letter T, whilst all pointer types start with the letter P. Both
  23.  the object instances and the actual pointer variables have names
  24.  appropriate to the circumstances of use.  Thus typical variable
  25.  declarations are:
  26.   VAR
  27.    Window: PDemoWindow;         {see page 32 of the Turbo Vision Guide}
  28.    R: TRect;
  29.  The extended syntax of 'New' also allows it to be used as a function,
  30.  returning a pointer value.  An example taken from page 32 of the Guide is:
  31.  
  32.       Window := New(PDemoWindow,    Init( R,   'Demo Window',WinCount));
  33.         |            |             /       \         |           |
  34.      Pointer      Pointer      Constructor  Object  Title      Number
  35.      variable     type         invocation   of type
  36.                                                TRect
  37.  
  38.  Thus Window is a pointer of type PDemoWindow, which itself has been
  39.  previously declared as:
  40.     TYPE
  41.       PDemoWindow = ^TDemoWindow;    { a pointer to type TDemoWindow }
  42.       TDemoWindow = OBJECT(TWindow)  { a simple user-defined descendant }
  43.       END;                           { object of TWindow }
  44.  
  45.  Hence Window points to an object type TDemoWindow, which inherits the
  46.  fields and methods from the ancestor object type TWindow (see pages
  47.  321-325).  The 'Init' method for TWindow is a static method and is defined
  48.  on page 322.  Three parameters are required, namely the bounds, a title and
  49.  a number.
  50.  The bounds are given by the parameter R, which is of type TRect (see page
  51.  278), whose data fields define the corners at the top left (A) and the
  52.  bottom right (B) of the rectangle.  One of TRect's (static) methods is the
  53.  Assign procedure, which gives the coordinates to the points A and B as XA,
  54.  YA, XB, YB (each of type integer).
  55.  
  56.  The assignment is made using the conventional dot notation, so as on page
  57.  32 the statement is:
  58.  
  59.       R.Assign(0, 0, 26, 7);      { set initial size and position }
  60.  
  61.  The second parameter to a TWindow initialization is a literal title (in
  62.  single quotes) and this will be displayed at the top of the window, along
  63.  with the third parameter, the WinCount number.
  64.  
  65.  The declarations and assignments shown in the above few paragraphs
  66.  illustrate the existence in Turbo Vision of predefined objects, each with
  67.  its appropriate fields and methods, some of which are static and may be
  68.  used directly, whilst others are virtual and may be overridden.
  69.  
  70.  The way in which objects inherit from ancestor types is indicated in the
  71.  Turbo Vision object hierarchy shown on page 66 of the Turbo Vision Guide.
  72.  It is seen that the object type TWindow referred to in the preceding
  73.  paragraphs is part of this hierarchy tree:
  74.  
  75.       TObject --- TView -----
  76.                |          |--
  77.                |          |--
  78.                |          |--
  79.                |          |-- TGroup -----
  80.                                        |--
  81.                                        |-- TWindow -----
  82.                                                      |--
  83.  
  84.  Each of these object types is sufficiently defined for any user application
  85.  in Chapter 13 'Object reference' on pages 205-325.  The actual code is only
  86.  accessible as a compiled unit (.TPU file), the name of which is also shown
  87.  in the reference.  Thus the 'root' ancestor TObject (pages 267-8) is shown
  88.  to be part of OBJECTS.TPU, to have no fields and just three methods, Init,
  89.  Free (both static) and Done (virtual).
  90.  
  91.  Apart from TPoint and TRect (see below) all Turbo Vision's standard objects
  92.  are ultimately derived from TObject.  Any object that uses Turbo Vision's
  93.  streams facilities must trace its ancestry back to TObject.
  94.  
  95.  TView is found in VIEWS.TPU, it has 11 fields, including size and options,
  96.  and 64 methods, including Init, Done, Draw, Show and WriteLine (pages
  97.  306-321).
  98.  
  99.  TGroup is also in VIEWS.TPU, it has 4 fields and 29 methods (pages
  100.  235-244).
  101.  
  102.  Because units are used, it follows that there must be a USES statement at
  103.  the start of any application program to ensure that all the required TPUs
  104.  are called.  Chapter 12 'Unit cross reference' (pages 189-204) gives
  105.  details of all the units used by Turbo Vision.  Types, constants,
  106.  variables, procedures and functions are listed for each unit.
  107.  
  108.  Because of inheritance, it is possible that a method used by any object
  109.  type may not be its own, but that of an ancestor type.  It may therefore be
  110.  necessary to refer back through the hierarchy to find the definition of a
  111.  particular method.
  112.  
  113.  TPoint is a simple object type representing a point on the screen by its
  114.  only two fields X and Y. It has no methods and is thus only a record and is
  115.  the ultimate abstraction as far as screen display is concerned.
  116.  
  117.  TRect has two fields, A and B, both of type TPoint and 9 methods.
  118.  
  119.  Apart from the standard object hierarchy of Turbo Vision, there are a
  120.  number of other elements (types, constants, variables, procedures and
  121.  functions) which are defined in the Turbo Vision units.  These are listed
  122.  in Chapter 14, 'Global reference' on pages 327-384 and include for example:
  123.  
  124.  TYPE      PString       defines a pointer to a string         OBJECTS.TPU
  125.            PtrRec        record of ofs & seg of a pointer      OBJECTS.TPU
  126.  
  127.  CONSTANT  hcXXXX        help context constants                VIEWS.TPU
  128.            ofXXXX        options flags                         VIEWS.TPU
  129.  
  130.  VARIABLE  ScreenHeight  height in lines of current screen     DRIVERS.TPU
  131.            MenuBar       stores a pointer to menu bar          APP.TPU
  132.  
  133.  PROCEDURE DisposeMenu   disposes all elements of the menu     OBJECTS.TPU
  134.            ClearScreen   clears the screen                     DRIVERS.TPU
  135.  
  136.  FUNCTION  NewStatusDef  returns a pointer to a new
  137.                          TStatusDef record                     MENUS.TPU
  138.  
  139.  
  140.  
  141.  Turbo Vision examples.
  142.  ----------------------
  143.  
  144.  Now that the structure of Turbo Vision and the notation has been
  145.  presented, it is possible to proceed with discussion of a specific example,
  146.  which relates to a screen display like that of the Turbo Pascal Integrated
  147.  Development Environment.  The display has a working area called the
  148.  Desktop, which occupies most of the screen, a Menu Bar at the top and a
  149.  Status Line at the bottom, which provides the user with advice on how to
  150.  proceed, even if it is only - Alt-X Exit.
  151.  
  152.  The example is described in detail in Chapter 2 of the Turbo Vision Guide
  153.  (pages 23- 28).  The program is in TVGUID01.PAS which is included with the
  154.  demo programs on the distribution disks and is listed below:
  155.  
  156.  PROGRAM TFirst;
  157.  
  158.  USES App;                            { application objects are in APP.TPU }
  159.  
  160.  TYPE TMyApp = OBJECT(TApplication)   { define new application type leaving }
  161.       END;                            { room for future expansion }
  162.  
  163.  VAR MyApp : TMyApp;                  { create an instance of the new type }
  164.  
  165.  BEGIN
  166.    MyApp.Init                         { set it up }
  167.    MyApp.Run                          { interact with the user